package com.bdqn.service.impl;

import com.bdqn.mapper.HisPatientMapper;
import com.bdqn.pojo.HisPatient;
import com.bdqn.pojo.HisRegistration;
import com.bdqn.service.HisPatientService;
import com.bdqn.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class HisPatientServiceImpl implements HisPatientService {
    @Autowired
    HisPatientMapper hisPatientMapper;
    @Autowired
    RandomUtil randomUtil;
    @Override
    public HisPatient getIdCardAll(String idCard) {
        return hisPatientMapper.selectidCardAll(idCard);
    }

    @Override
    public HisPatient getIdNameAll(String name) {
        return hisPatientMapper.selectNameAll(name);
    }

    @Override
    public String addHisPatient(HisPatient hisPatient) {
        String patientId = randomUtil.randomPatient();
        String isFinal = "1";
        hisPatient.setPatientId(patientId);
        hisPatient.setIsFinal(isFinal);
        String idCard = hisPatient.getIdCard();
        int row = hisPatientMapper.addHisPatient(hisPatient);
        if (row>0){
            return patientId;
        }else {
            return null;
        }
    }

    @Override
    public HisPatient receiveAPatientForTreatment(String id) {
        return hisPatientMapper.receiveAPatientForTreatment(id);
    }
}
